#include "PlayerDetailContent.h"
#include "../../model/proxy/UserProxy.h"
#include "../../model/vo/DataVO.h"
#include "../../utils/LocalString.h"
#include "../../model/proxy/ItemProxy.h"

PlayerDetailContent::PlayerDetailContent(void)
	:mName(NULL),mSex(NULL),mLevel(NULL),mExp(NULL),mCoin(NULL),mMoney(NULL),mEnergy(NULL)
	,mNextEnergyTime(NULL),mAllEnergyTime(NULL),mPower(NULL),mNextPowerTime(NULL),mAllPowerTime(NULL),mCurLife(NULL),mAddLife(NULL)
	,mCurEnergy(NULL),mAddEnergy(NULL),mProficiency(NULL),mPutonCount(NULL),mLife(NULL),mAttack(NULL),mDefense(NULL)
	,mAtkMaxReappear(NULL),mDefMaxReappear(NULL),mExpGainRatio(NULL),mCoinGainRatio(NULL),mEquipageDropRatio(NULL),mPowerRecoverRatio(NULL),mEnergyRecoverRatio(NULL)
{
}

PlayerDetailContent::~PlayerDetailContent(void)
{
	CC_SAFE_RELEASE(mName);CC_SAFE_RELEASE(mSex);CC_SAFE_RELEASE(mLevel);CC_SAFE_RELEASE(mExp);
	CC_SAFE_RELEASE(mCoin);CC_SAFE_RELEASE(mMoney);CC_SAFE_RELEASE(mEnergy);CC_SAFE_RELEASE(mNextEnergyTime);
	CC_SAFE_RELEASE(mAllEnergyTime);CC_SAFE_RELEASE(mPower);CC_SAFE_RELEASE(mNextPowerTime);CC_SAFE_RELEASE(mAllPowerTime);
	CC_SAFE_RELEASE(mCurLife);CC_SAFE_RELEASE(mAddLife);CC_SAFE_RELEASE(mCurEnergy);CC_SAFE_RELEASE(mAddEnergy);
	CC_SAFE_RELEASE(mProficiency);CC_SAFE_RELEASE(mPutonCount);CC_SAFE_RELEASE(mLife);CC_SAFE_RELEASE(mAttack);
	CC_SAFE_RELEASE(mDefense);CC_SAFE_RELEASE(mAtkMaxReappear);CC_SAFE_RELEASE(mDefMaxReappear);CC_SAFE_RELEASE(mExpGainRatio);
	CC_SAFE_RELEASE(mCoinGainRatio);CC_SAFE_RELEASE(mEquipageDropRatio);CC_SAFE_RELEASE(mPowerRecoverRatio);CC_SAFE_RELEASE(mEnergyRecoverRatio);
}

bool PlayerDetailContent::init()
{
	return true;
}

SEL_MenuHandler PlayerDetailContent::onResolveCCBCCMenuItemSelector(CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCMENUITEM_GLUE(this, "onDoItClick", PlayerDetailContent::onDoItClick);
	return NULL;
}

SEL_CCControlHandler PlayerDetailContent::onResolveCCBCCControlSelector( CCObject * pTarget, CCString * pSelectorName )
{
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAvatarBtnClick", PlayerDetailContent::onAvatarBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAddLifeBtnClick", PlayerDetailContent::onAddLifeBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSubLifeBtnClick", PlayerDetailContent::onSubLifeBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAddEnergyBtnClick", PlayerDetailContent::onAddEnergyBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onSubEnergyBtnClick", PlayerDetailContent::onSubEnergyBtnClick);
	CCB_SELECTORRESOLVER_CCCONTROL_GLUE(this, "onAddOkBtnClick", PlayerDetailContent::onAddOkBtnClick);
	return NULL;
}

bool PlayerDetailContent::onAssignCCBMemberVariable( CCObject * pTarget, CCString * pMemberVariableName, CCNode * pNode )
{
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mName", CCLabelTTF *, this->mName);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mSex", CCLabelTTF *, this->mSex);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mLevel", CCLabelTTF *, this->mLevel);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mExp", CCLabelTTF *, this->mExp);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCoin", CCLabelTTF *, this->mCoin);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mMoney", CCLabelTTF *, this->mMoney);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mEnergy", CCLabelTTF *, this->mEnergy);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mNextEnergyTime", CCLabelTTF *, this->mNextEnergyTime);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAllEnergyTime", CCLabelTTF *, this->mAllEnergyTime);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mPower", CCLabelTTF *, this->mPower);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mNextPowerTime", CCLabelTTF *, this->mNextPowerTime);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAllPowerTime", CCLabelTTF *, this->mAllPowerTime);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCurLife", CCLabelTTF *, this->mCurLife);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAddLife", CCLabelTTF *, this->mAddLife);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCurEnergy", CCLabelTTF *, this->mCurEnergy);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAddEnergy", CCLabelTTF *, this->mAddEnergy);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mProficiency", CCLabelTTF *, this->mProficiency);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mPutonCount", CCLabelTTF *, this->mPutonCount);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mLife", CCLabelTTF *, this->mLife);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAttack", CCLabelTTF *, this->mAttack);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDefense", CCLabelTTF *, this->mDefense);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mAtkMaxReappear", CCLabelTTF *, this->mAtkMaxReappear);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mDefMaxReappear", CCLabelTTF *, this->mDefMaxReappear);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mExpGainRatio", CCLabelTTF *, this->mExpGainRatio);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mCoinGainRatio", CCLabelTTF *, this->mCoinGainRatio);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mEquipageDropRatio", CCLabelTTF *, this->mEquipageDropRatio);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mPowerRecoverRatio", CCLabelTTF *, this->mPowerRecoverRatio);
	CCB_MEMBERVARIABLEASSIGNER_GLUE(this, "mEnergyRecoverRatio", CCLabelTTF *, this->mEnergyRecoverRatio);


	return false;
}

void PlayerDetailContent::onNodeLoaded( CCNode * pNode, CCNodeLoader * pNodeLoader )
{
	
}

void PlayerDetailContent::onEnter()
{
	CCNode::onEnter();
	refresh();
}

void PlayerDetailContent::onExit()
{
	CCNode::onExit();
}

void PlayerDetailContent::refresh()
{
	UserVO& userVO = UserProxy::getSingletonPtr()->userVO;
	mCurLifeValue = userVO.life;
	mAddLifeValue = 0;
	mCurEnergyValue = userVO.energyMax;
	mAddEnergyValue = 0;
	mCurProficiency = userVO.proficiency;
	mMaxProficiency = userVO.proficiency;
	mName->setString(userVO.name.c_str());
	if(userVO.sex==0)
		mSex->setString(gls("sex_man"));
	else
		mSex->setString(gls("sex_woman"));
	mLevel->setString(fcs("%d", userVO.level));
	mExp->setString(fcs("%d", userVO.exp));
	mCoin->setString(fcs("%d", userVO.coin));
	mMoney->setString(fcs("%d", userVO.money));
	mEnergy->setString(fcs("%d/%d", userVO.energyCur, userVO.energyMax));
	mNextEnergyTime->setString("00:56:20");
	mAllEnergyTime->setString("00:56:20");
	mPower->setString(fcs("%d", userVO.powerCur, userVO.powerMax));
	mNextPowerTime->setString("00:56:20");
	mAllPowerTime->setString("00:56:20");
	mCurLife->setString(fcs("%d", mCurLifeValue));
	mAddLife->setString(fcs("%d", mAddLifeValue));
	mCurEnergy->setString(fcs("%d", mCurEnergyValue));
	mAddEnergy->setString(fcs("%d", mAddEnergyValue));
	mProficiency->setString(fcs("%d", mCurProficiency));
	mPutonCount->setString(fcs("%d/%d", ItemProxy::getSingletonPtr()->getPutonCount(),
		ItemProxy::getSingletonPtr()->getEquipCount()));
	mLife->setString(fcs("%d", userVO.life));
	mAttack->setString(fcs("%d-%d", userVO.atkMin, userVO.atkMax));
	mDefense->setString(fcs("%d-%d", userVO.defMin, userVO.defMax));
	mAtkMaxReappear->setString(fcs("%d%%", userVO.atkMaxReappear));
	mDefMaxReappear->setString(fcs("%d%%", userVO.defMaxReappear));
	mExpGainRatio->setString(fcs("%d%%", userVO.expGainRatio));
	mCoinGainRatio->setString(fcs("%d%%", userVO.coinGainRatio));
	mEquipageDropRatio->setString(fcs("%d%%", userVO.equipageDropRatio));
	mPowerRecoverRatio->setString(fcs("%d%%", userVO.powerRecoverRatio));
	mEnergyRecoverRatio->setString(fcs("%d%%", userVO.energyRecoverRatio));
}

void PlayerDetailContent::_onNotification( CCObject* object )
{
	
}

void PlayerDetailContent::onDoItClick(CCObject* pSender)
{
    
}

void PlayerDetailContent::onAvatarBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{

}

void PlayerDetailContent::onAddLifeBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	if (mCurProficiency <= 0) return;
	mCurProficiency--;
	mCurLifeValue++;
	mAddLifeValue++;
	mCurLife->setString(fcs("%d", mCurLifeValue));
	mAddLife->setString(fcs("%d", mAddLifeValue));
	mProficiency->setString(fcs("%d", mCurProficiency));

}

void PlayerDetailContent::onSubLifeBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	if (mAddLifeValue <= 0) return;
	mCurProficiency++;
	mCurLifeValue--;
	mAddLifeValue--;
	mCurLife->setString(fcs("%d", mCurLifeValue));
	mAddLife->setString(fcs("%d", mAddLifeValue));
	mProficiency->setString(fcs("%d", mCurProficiency));
}

void PlayerDetailContent::onAddEnergyBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	if (mCurProficiency <= 0) return;
	mCurProficiency--;
	mCurEnergyValue++;
	mAddEnergyValue++;
	mCurEnergy->setString(fcs("%d", mCurEnergyValue));
	mAddEnergy->setString(fcs("%d", mAddEnergyValue));
	mProficiency->setString(fcs("%d", mCurProficiency));
}

void PlayerDetailContent::onSubEnergyBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{
	if (mAddEnergyValue <= 0) return;
	mCurProficiency++;
	mCurEnergyValue--;
	mAddEnergyValue--;
	mCurEnergy->setString(fcs("%d", mCurEnergyValue));
	mAddEnergy->setString(fcs("%d", mAddEnergyValue));
	mProficiency->setString(fcs("%d", mCurProficiency));
}

void PlayerDetailContent::onAddOkBtnClick( CCObject * pSender, CCControlEvent pCCControlEvent )
{

}
